package cn.xz.tipsum.activity

import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.WindowManager
import androidx.databinding.DataBindingUtil
import cn.xz.tipsum.R
import cn.xz.tipsum.databinding.ActivitySettingBinding
import cn.xz.tipsum.utils.AppHelper
import cn.xz.tipsum.utils.MD5Utils
import cn.xz.tipsum.utils.SessionUtils
import cn.xz.tipsum.whight.YColorView

class SettingActivity : AppCompatActivity() {

    private lateinit var mDataBind: ActivitySettingBinding

    private var mSW: Boolean = true

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
        mDataBind = DataBindingUtil.setContentView(this, R.layout.activity_setting)
        initData()
        initEvent()
    }

    private fun initData(){
        setWColor(SessionUtils.getInt(SessionUtils.COLOR_WX,Color.parseColor("#228B22")))
        setZColor(SessionUtils.getInt(SessionUtils.COLOR_ZFB,Color.parseColor("#1E90FF")))
    }

    private fun initEvent(){
        mDataBind.apply {
            tvBack.setOnClickListener {
                finish()
            }
            yv.addOnYColorListener {
               if (mSW)  setWColor(it) else setZColor(it)

            }
            llcSw.setOnClickListener {
                mSW = true
                tvWt.setTextColor(Color.parseColor("#FFFFFF"))
                tvZt.setTextColor(Color.parseColor("#999999"))
            }
            llcSz.setOnClickListener {
                mSW = false
                tvWt.setTextColor(Color.parseColor("#999999"))
                tvZt.setTextColor(Color.parseColor("#FFFFFF"))
            }
        }
    }

    //微颜色
    private fun setWColor(color: Int){
        mDataBind.apply {
            viewW.post {
                viewW.setBackgroundColor(color)
                tvW11.setTextColor(color)
                tvW12.setTextColor(color)
                tvW13.setTextColor(color)
                tvW31.setTextColor(color)
                tvW32.setTextColor(color)
                tvW33.setTextColor(color)
            }
        }
        SessionUtils.commitInt(SessionUtils.COLOR_WX,color)
    }

    //支颜色
    private fun setZColor(color: Int){
        mDataBind.apply {
            viewZ.post {
                viewZ.setBackgroundColor(color)
                tvZ21.setTextColor(color)
                tvZ22.setTextColor(color)
                tvZ23.setTextColor(color)
                tvZ41.setTextColor(color)
                tvZ42.setTextColor(color)
                tvZ43.setTextColor(color)
            }
        }
        SessionUtils.commitInt(SessionUtils.COLOR_ZFB,color)
    }

}